package com.ljf.daily.consumptiondetail.infra.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.infra.repository.impl.BasisRepositoryImpl;
import com.ljf.daily.consumptiondetail.domain.repository.DailyDatConsumptionDetailRepository;
import com.ljf.daily.consumptiondetail.dto.query.DailyDatConsumptionDetailQuery;
import com.ljf.daily.consumptiondetail.infra.mapper.DailyDatConsumptionDetailMapper;
import com.ljf.daily.consumptiondetail.model.DailyDatConsumptionDetail;
import com.ljf.daily.consumptiondetail.vo.DailyDatConsumptionDetailVO;
import org.springframework.stereotype.Component;

/**
 * 日常消费明细  数据访问接口实现
 *
 * @author LJF
 * @since 2024-05-15
 */
@Component
public class DailyDatConsumptionDetailRepositoryImpl extends BasisRepositoryImpl<DailyDatConsumptionDetailMapper, DailyDatConsumptionDetail, DailyDatConsumptionDetailQuery, DailyDatConsumptionDetailVO> implements DailyDatConsumptionDetailRepository {

    @Override
    protected QueryWrapper<DailyDatConsumptionDetail> fillWrapper(DailyDatConsumptionDetailQuery query, boolean sort) throws ServiceException {
        QueryWrapper<DailyDatConsumptionDetail> wrapper = super.fillWrapper(query, false);
        if (query.getBelongDateStart() != null || query.getBelongDateEnd() != null) {
            if (query.getBelongDateStart() != null && query.getBelongDateEnd() != null) {
                wrapper.between(DailyDatConsumptionDetail.COL_BELONG_DATE, query.getBelongDateStart(), query.getBelongDateEnd());
            }
            else {
                throw new ServiceException("查询异常:请选择时间范围");
            }
        }
        wrapper.orderByDesc(DailyDatConsumptionDetail.COL_BELONG_DATE);
        return wrapper;
    }
}
